package com.hua.comm.base.basePresenter;


import com.hua.comm.base.baseModel.IBaseModel;
import com.hua.comm.base.baseView.IBaseView;

public class BasePresenter<V extends IBaseView, M extends IBaseModel> implements IBasePresenter<V, M> {

    protected V mView; // 弱引用View，避免内存泄漏（实际项目建议用WeakReference）
    protected M mModel; // Model实例

    public BasePresenter(M model) {
        this.mModel = model;
    }

    @Override
    public void attachView(V view) {
        this.mView = view;
    }

    @Override
    public void detachView() {
        this.mView = null;
    }

    @Override
    public M getModel() {
        return mModel;
    }

    // 判断View是否已绑定（防止页面销毁后回调）
    protected boolean isViewAttached() {
        return mView != null;
    }
}
